<%-- 
    Document   : PedidoFeito
    Created on : 01/06/2014, 10:26:49
    Author     : Julio
--%>

<%@page import="java.util.Date"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Pedido Finalizado</title>
        
        <style>
            #campototal{
                text-align: center;
                font: bold 20px/45px sans-serif;
                background-color: #54FF9F;
                width: 800px;
                height: 200px;
                margin-top: 100px;
                border-bottom-color: black;
                border-radius: 10px;
                
                
            }
            #botao1{
                margin-left: 100px;
                margin-top: 30px;
            }
            
            
            .botao1{
     background: -webkit-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -moz-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -o-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -ms-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     border: 1px solid #CCCCCE;
     border-radius: 3px;
     box-shadow: 0 3px 0 rgba(0, 0, 0, .3),
                   0 2px 7px rgba(0, 0, 0, 0.2);
     color: #616165;
     display: block;
     font-family: "Trebuchet MS";
     font-size: 14px;
     font-weight: bold;
     line-height: 25px;
     text-align: center;
     text-decoration: none;
     text-transform: uppercase;
     text-shadow:1px 1px 0 #FFF;
     padding: 5px 15px;
     position: relative;
     width: 100px;
     border-radius: 20px;
     margin-left: 100px;
     float: left;
    }
    
    .botao2{
     background: -webkit-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -moz-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -o-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: -ms-linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     background: linear-gradient(bottom, #E0E0E0, #F9F9F9 70%);
     border: 1px solid #CCCCCE;
     border-radius: 3px;
     box-shadow: 0 3px 0 rgba(0, 0, 0, .3),
                   0 2px 7px rgba(0, 0, 0, 0.2);
     color: #616165;
     display: block;
     font-family: "Trebuchet MS";
     font-size: 14px;
     font-weight: bold;
     line-height: 25px;
     text-align: center;
     text-decoration: none;
     text-transform: uppercase;
     text-shadow:1px 1px 0 #FFF;
     padding: 5px 15px;
     position: relative;
     width: 100px;
     border-radius: 20px;
     margin-left: 400px;
     
    }
        </style>
        
    </head>
    <body>
    <center>
        <div id="campototal">
            <% 
             String pão=request.getParameter("txt_pão");
             String queijo=request.getParameter("txt_queijo");
             String recheio=request.getParameter("txt_recheio");
             String salada=request.getParameter("txt_salada");
             //String queijo=request.getParameter("txt_queijo");
             Connection con=null;
             Statement stmt=null;
             ResultSet rs=null;
             try{
                 Class.forName("oracle.jdbc.driver.OracleDriver");
                 con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
                 stmt=con.createStatement();
                 PreparedStatement ps = null;
                 rs=stmt.executeQuery("SELECT MAX(cd_item) FROM item_pedido");
                 while(rs.next()){
                     int i=(rs.getInt("cd_item"))+1;
                 }
                 rs=stmt.executeQuery("SELECT MAX(cd_pedido) FROM pedido");
                 while(rs.next()){
                     int p=(rs.getInt("cd_pedido"))+1;
                 }
                 
                 ps = con.prepareStatement("INSERT INTO item_pedido values('"+i+"','"+p+"','"+pão+"',1");
                 ps.execute();
                 rs=stmt.executeQuery("SELECT MAX(cd_item) FROM item_pedido");
                 while(rs.next()){
                     int i=(rs.getInt("cd_item"))+1;
                 }
                 ps = con.prepareStatement("INSERT INTO item_pedido values('"+i+"','"+p+"','"+queijo+"',2");
                 ps.execute();
                 
                 rs=stmt.executeQuery("SELECT MAX(cd_item) FROM item_pedido");
                 while(rs.next()){
                     int i=(rs.getInt("cd_item"))+1;
                 }
                 ps = con.prepareStatement("INSERT INTO item_pedido values('"+i+"','"+p+"','"+recheio+"',3");
                 ps.execute();
                 
                 rs=stmt.executeQuery("SELECT MAX(cd_item) FROM item_pedido");
                 while(rs.next()){
                     int i=(rs.getInt("cd_item"))+1;
                 }
                 ps = con.prepareStatement("INSERT INTO item_pedido values('"+i+"','"+p+"','"+salada+"',4");
                 ps.execute();
                 
                String cpf=(String)session.getAttribute("cpf");
                 Date data= new java.sql.Date(new Date().getTime());
                 ps = con.prepareStatement("INSERT INTO pedido values('"+p+"','"+data+"','p',','"+cpf+"',''");
                 ps.execute();
                 
                 
             }catch(Exception e){
                 out.println("ERRO");
             }finally{
                 rs.close();
                 stmt.close();
             } %>
            
            Pedido Finalizado Com Sucesso !!!
            
            <div id="botao1" >
                 <a href="NovoPedido.jsp" class="botao1">Fazer Outro Pedido</a>
            </div>
            
            <div id="botao2">
                <a href="Inicio.jsp" class="botao2">Voltar para o Início</a>
            </div>    
            
            
        </div> 
    </center>  
        
        
        
    </body>
</html>
